﻿define(['api','CustomerEdit'],function (api,CustomerEdit) {
    var CustomerInfo = {
        name: 'customer-info',
        template: ''
        + '<div class="leftInfo">'
        + ' <div class="leftInfo-header"><span>客户资料</span></div>'
        + ' <div class="leftInfo-content">'
        + '     <ul>'
        + '         <li><span>客户姓名</span><p><i>{{customerInfo.NameText}}</i></p></li>'
        + '         <li><span>客户属性</span><p><i>{{PoolType}}</i></p></li>'
        + '         <li><span>销售员</span><p><i>{{customerInfo.NodeName}}</i></p></li>'
        + '         <li><span>是否成交</span><p><i>{{customerInfo.HasTraded}}</i></p></li>'
        + '         <li><span>添加时间</span><p><i>{{customerInfo.AddTime}}</i></p></li>'
        + '         <li><span>省份城市</span><p><i>{{customerInfo.AdministrativeDivisionName}}</i></p></li>'
        + '         <li><span>联系方式</span><p><i>{{customerInfo.Phone}}</i></p></li>'
        + '         <li><span>客户来源</span><p><i>{{customerInfo.SourceType}}</i></p></li>'
        + '         <li><span>来源终端</span><p><i>{{customerInfo.SourceClientName}}</i></p></li>'
        + '         <li><span>意向房源</span><p><i>{{customerInfo.IntentionHouse}}</i></p></li>'
        + '         <li class="tag1"><span>客户标签</span><p>'
        + '             <em class="tag-blue" v-for="item in customerInfo.LastVisitCustomProperty">{{item}}</em></p>'
        + '         </li>'
        + '         <li class="tag2"><span>初始需求</span><p><i>{{customerInfo.CustomerInitialDemand}}</i></p></li>'
        + '         <li><span>客户备注</span><p><i>{{customerInfo.Remark}}</i></p></li>'
        + '         <li><span>客户等级</span><p><i>{{customerInfo.LevelName}}</i></p></li>'
        + '     </ul>'
        + ' </div>'
        + ' <div class="leftInfo-footer" v-if="poolType!=\'RecyclePool\'">'
        + '     <Button type="primary" v-on:click="clickCustomerEdit" style="padding-top: 0px;padding-right: 0px; padding-left: ‒24;padding-bottom: 0px;">修改客户资料</Button>'
        + ' </div>'
        + ' <customer-edit  v-bind:pool-type="poolType"></customer-edit>'
        + '</div>',
        props: {
            poolType: String
        },
        data: function () {
            return {
                customerInfo: {
                    Name: "",
                    NameText: "",
                    NodeName: "",
                    HasTraded: '否',
                    AddTime: "",
                    AdministrativeDivisionName: "",
                    Phone: "",
                    CustomerInitialDemand: "",
                    Remark: "",
                    IntentionHouse: "",
                    SourceClient: "",
                    SourceType: "",
                    LevelName: "",
                    Gender: "",
                    LastVisitCustomProperty:[],
                },
                customerId: "",
                PoolType: this.poolType === "StaffPool" ? "个人客户" : "公共客户",
            }
        },
        mounted: function () {
            var thisInfo = this;
            //监听getCustomerDetail
            window.bus.$on("getCustomerDetail", function (Id) {
                thisInfo.customerId = Id;
                thisInfo.getInfo(Id);
            });
            //监听saveCustomerEditSuccess
            window.bus.$on("saveCustomerEditSuccess", function (Id) {
                thisInfo.getInfo(Id);
            });
        },
        computed: {

        },
        components: {
            CustomerEdit: CustomerEdit
        },
        methods: {
            clickCustomerEdit: function () {
                //触发showCustomerEdit
                window.bus.$emit("showCustomerEdit", this.customerId);
            },
            getInfo: function (Id) {
                var thisInfo = this;
                api.Get_Customer_Info({customerId: Id})
                    .done(function (data) {
                        if (data.IsSuccess) {
                            thisInfo.customerInfo = data.ResultObject;
                        } else {
                            thisInfo.$Message.error(data.ErrMsg);
                        }
                    })
                    .fail(function () {
                        thisInfo.$Message.error('查询出错');
                    })
            }
        },
    };
    return CustomerInfo;
});
